package controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import service.ComplaintAuditManager;

@Controller
@RequestMapping("/complaint")
public class OrderComplaintController {
	
	@Autowired
	private ComplaintAuditManager cam;
	
	@RequestMapping("/list")
	public String listComplaint(Model model){
		model.addAttribute("complaintList", cam.listAllComplaint());
		return "order_complaint";
	}
	
	@RequestMapping("/audit/{oId}/{status}")
	@ResponseBody
	public String auditComplaint(@PathVariable String oId, @PathVariable int status){
		String sign = cam.auditComplaint(oId, status);
		if(!sign.equals("0") && sign != null){
			return "{\"msg\":\"SUCCESS\"}";
		}else {			
			return "{\"error\":\"Operation failed\"}";
		}
	}
	
	@RequestMapping("/listByM/{mId}")
	@ResponseBody
	public Map<String, Integer> listComplaintByMId(@PathVariable String mId){
		return cam.listMerchantComplaint(mId);
	}
	
	@RequestMapping("/listByC/{cId}")
	@ResponseBody
	public Map<String, Integer> listComplaintByCId(@PathVariable String cId){
		return cam.listClientComplaint(cId);
	}
}
